package com.dudetest.data.objectify.independent;

import com.dudetest.data.DAOVersion;
import com.dudetest.data.objectify.DAOBase;
import com.dudetest.dude.DudeA;
import com.dudetest.dude.DudeAB;
import com.googlecode.objectify.ObjectifyOpts;
import com.googlecode.objectify.ObjectifyService;

public class DAOObjectifyIndependent extends DAOBase {

	static {
		ObjectifyService.register(DudeAIndependent.class);
		ObjectifyService.register(DudeABIndependent.class);
	}
	
	//##############
	// Constructors
	//##############
	
	public DAOObjectifyIndependent(){
		super();
	}

	public DAOObjectifyIndependent(boolean transactional){
		super(transactional);
	}

	public DAOObjectifyIndependent(ObjectifyOpts opts){
		super(opts);
	}
	
	//#############
	// Methods
	//#############
	
	@Override
	public DudeA getOrCreateDudeA(long id){
		DudeA d = null;
		if((d = this.getDudeA(id)) == null){
			d = new DudeAIndependent(id);
			ofy().put(d);
		}
		return d;
	}

	@Override
	public DudeAB getOrCreateDudeAB(long id){
		DudeAB d = null;
		if((d = this.getDudeAB(id)) == null){
			d = new DudeABIndependent(id);
			ofy().put(d);
		}
		return d;
	}

	//############
	// Getters & Setters
	//############

	@Override
	public DudeA getDudeA(long key) {
		return ofy().find(DudeAIndependent.class,key);
	}

	@Override
	public DudeAB getDudeAB(long key) {
		return ofy().find(DudeABIndependent.class,key);
	}

	@Override
	public DAOVersion getVersion() {
		return DAOVersion.SUBCLASSED;
	}
}
